﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;
namespace yeqw.FrameWork
{
    [AttributeUsage(AttributeTargets.Property, Inherited = true)]
    public class ModelDataAttribute:Attribute
    {
        public enum EnumValidateType : byte
        {
            IsNull,
            IsNumber,
            IsMaxLength
        }
        public bool CanNull
        {
            set;
            get;
        }
        public string SQLFieldName
        {
            set;
            get; 
        }
        public SqlDbType SQLDbType
        {
           
            set;
            get;
        }

        public int SQLSize
        {
            set;
            get;
        }
        public ParameterDirection SQLParameterDirection
        {
            set;
            get;
        }

        public string Message
        {
            set;
            get;
        }

        public ModelDataAttribute(string sqlFieldName, SqlDbType sqlParameterType)
            : this(sqlFieldName, sqlParameterType, 0)
        { }

        public ModelDataAttribute(string sqlFieldName, SqlDbType sqlParameterType, int sqlparametersize)
            : this(sqlFieldName, sqlParameterType, sqlparametersize, ParameterDirection.Input)
         {}
            
        public ModelDataAttribute(string sqlFieldName,SqlDbType sqlParameterType, int sqlparametersize,ParameterDirection sqlParameterDirection)
        {
            SQLFieldName = sqlFieldName;
            SQLDbType = sqlParameterType;
            SQLSize = sqlparametersize;
            SQLParameterDirection = sqlParameterDirection;
        
        }

        public void Validate(object value)
        {
            if (!CanNull)
            { 
                if(string.IsNullOrEmpty(value.ToString()))
                {
                    throw new ArgumentException(Message);
                }
            }
        }
        
    }
}
